package tamavo.dao
{
	import mx.collections.ArrayCollection;
	import mx.rpc.events.ResultEvent;
	import mx.utils.ArrayUtil;
	
	import tamavo.context.Context;
	import tamavo.entities.Process;

	public class ProcessDAO
	{
		private var event:ResultEvent;
		
		public function ProcessDAO(){
			event = Context.getAttribute("eventXML");
		}
		
		public function findAll():ArrayCollection{
			var ac:ArrayCollection = new ArrayCollection();
			for each(var p:Object in event.result.tbd.processes.process){
				ac.addItem(processRow(p));
			}
			return ac;
		}
		
		public function findById(id:String):Process{
			for each(var p:Object in event.result.tbd.processes.process){
				if(p.id == id)
					return processRow(p) as Process;
			}
			return null;
		}
		
		protected function processRow(o:Object):Object{
			var proc:Process = new Process();
			proc.id = o.id;
			proc.name = o.name;
			proc.command = o.command;
			proc.arguments = o.arguments;
			proc.status = Process.STOPPED;
			return proc;
		}
	}
}